package easy.二叉树的中序遍历;

import java.util.ArrayList;
import java.util.List;

/**
 * 二叉树的中序遍历
 *
 * @author CodeX
 * @since 2021-09-29 14:53:59
 */
public class InorderTraversal {

    public static List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> ans = new ArrayList<>();
        getChild(root, ans);
        return ans;
    }

    public static void getChild(TreeNode root, List<Integer> ans) {
        if (root == null) {
            return;
        }
        getChild(root.left, ans);
        ans.add(root.val);
        getChild(root.right, ans);
    }

    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(3);
        root.right = new TreeNode(2);
        System.out.println(inorderTraversal(root));
    }
}
